home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WW3DKit / usefulWW3DFunctions.c < prev    next >
Encoding:
Text File  |  1995-03-22  |  2.8 KB  |  86 lines

  1. #import <appkit/appkit.h>
  2. #import <3Dkit/3Dkit.h>
  3.  
  4. // here's the deal.  Given a bounding box, we're going to transform that
  5. // by the given transformation matrix.  Since this effects the extent
  6. // of the object, we have to transform all 8 points of the bounding box.
  7. // After transforming them, we then redetermine the min and max of things
  8. // orthogonal to the current origin.
  9. // it's fine if newBB and aBB point to the same boundingBox...
  10.  
  11. // really should look at Arvo's Gem, p 548 of GG1...
  12.  
  13. void
  14. WW3DDetermineBoundGivenBoundAndCTM(RtBound *newBB, RtBound *aBB, RtMatrix aCTM) 
  15. {
  16.    RtPoint  bboxPoints[8], bboxPointsTransformed[8];
  17.    int      i;
  18.             
  19.  
  20.    N3D_XComp(bboxPoints[0]) = (*aBB)[0];
  21.    N3D_YComp(bboxPoints[0]) = (*aBB)[2];
  22.    N3D_ZComp(bboxPoints[0]) = (*aBB)[4];
  23.  
  24.    N3D_XComp(bboxPoints[1]) = (*aBB)[1];
  25.    N3D_YComp(bboxPoints[1]) = (*aBB)[2];
  26.    N3D_ZComp(bboxPoints[1]) = (*aBB)[4];
  27.  
  28.    N3D_XComp(bboxPoints[2]) = (*aBB)[0];
  29.    N3D_YComp(bboxPoints[2]) = (*aBB)[3];
  30.    N3D_ZComp(bboxPoints[2]) = (*aBB)[4];
  31.  
  32.    N3D_XComp(bboxPoints[3]) = (*aBB)[1];
  33.    N3D_YComp(bboxPoints[3]) = (*aBB)[3];
  34.    N3D_ZComp(bboxPoints[3]) = (*aBB)[4];
  35.  
  36.    N3D_XComp(bboxPoints[4]) = (*aBB)[0];
  37.    N3D_YComp(bboxPoints[4]) = (*aBB)[2];
  38.    N3D_ZComp(bboxPoints[4]) = (*aBB)[5];
  39.  
  40.    N3D_XComp(bboxPoints[5]) = (*aBB)[1];
  41.    N3D_YComp(bboxPoints[5]) = (*aBB)[2];
  42.    N3D_ZComp(bboxPoints[5]) = (*aBB)[5];
  43.  
  44.    N3D_XComp(bboxPoints[6]) = (*aBB)[0];
  45.    N3D_YComp(bboxPoints[6]) = (*aBB)[3];
  46.    N3D_ZComp(bboxPoints[6]) = (*aBB)[5];
  47.  
  48.    N3D_XComp(bboxPoints[7]) = (*aBB)[1];
  49.    N3D_YComp(bboxPoints[7]) = (*aBB)[3];
  50.    N3D_ZComp(bboxPoints[7]) = (*aBB)[5];
  51.  
  52.    N3DMult3DPoints(bboxPoints, 8, aCTM, bboxPointsTransformed);
  53.  
  54.    // start off setting newBB to be the first point
  55.    (*newBB)[0] = (*newBB)[1] = N3D_XComp(bboxPointsTransformed[0]);
  56.    (*newBB)[2] = (*newBB)[3] = N3D_YComp(bboxPointsTransformed[0]);
  57.    (*newBB)[4] = (*newBB)[5] = N3D_ZComp(bboxPointsTransformed[0]);
  58.  
  59.    for (i = 1; i < 8; i++)
  60.    {  //// X
  61.       if ((*newBB)[0] > N3D_XComp(bboxPointsTransformed[i]))
  62.       {  (*newBB)[0] = N3D_XComp(bboxPointsTransformed[i]);
  63.       }
  64.       if ((*newBB)[1] < N3D_XComp(bboxPointsTransformed[i]))
  65.       {  (*newBB)[1] = N3D_XComp(bboxPointsTransformed[i]);
  66.       }
  67.       //// Y
  68.       if ((*newBB)[2] > N3D_YComp(bboxPointsTransformed[i]))
  69.       {  (*newBB)[2] = N3D_YComp(bboxPointsTransformed[i]);
  70.       }
  71.       if ((*newBB)[3] < N3D_YComp(bboxPointsTransformed[i]))
  72.       {  (*newBB)[3] = N3D_YComp(bboxPointsTransformed[i]);
  73.       }
  74.       //// Z
  75.       if ((*newBB)[4] > N3D_ZComp(bboxPointsTransformed[i]))
  76.       {  (*newBB)[4] = N3D_ZComp(bboxPointsTransformed[i]);
  77.       }
  78.       if ((*newBB)[5] < N3D_ZComp(bboxPointsTransformed[i]))
  79.       {  (*newBB)[5] = N3D_ZComp(bboxPointsTransformed[i]);
  80.       }
  81.    }
  82.  
  83.    return ;
  84. }
  85.  
  86.